package com.tripcube.ai.controller;

import com.aliyun.bailian20231229.models.ListCategoryResponseBody;
import com.github.pagehelper.PageInfo;
import com.tripcube.ai.model.dto.CategoryCreatDTO;
import com.tripcube.ai.model.dto.CategorySelectDTO;
import com.tripcube.ai.model.entity.Category;
import com.tripcube.ai.service.CategoryService;
import com.tripcube.common.core.web.controller.BaseController;
import com.tripcube.common.core.web.domain.AjaxResult;
import com.tripcube.common.log.annotation.Log;
import com.tripcube.common.log.enums.BusinessType;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 类目管理
 *
 * @author alander
 */
@Tag(name = "类目管理", description = "阿里百炼类目管理相关接口")
@RestController
@RequestMapping("/ai/category")
@RequiredArgsConstructor
public class CategoryController extends BaseController {

    private final CategoryService categoryService;

    /**
     * 创建类目
     */
    @Operation(summary = "创建类目")
    @Log(title = "类目管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult addCategory(@RequestBody CategoryCreatDTO categoryCreatDTO) {
        Category category = categoryService.addCategory(categoryCreatDTO);
        return success(category);
    }

    /**
     * 删除类目
     */
    @Operation(summary = "删除类目")
    @Log(title = "类目管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{categoryId}")
    public AjaxResult deleteCategory(@PathVariable String categoryId) {
        boolean result = categoryService.deleteCategory(categoryId);
        return result ? success() : error();
    }

    /**
     * 批量删除类目
     */
    @Operation(summary = "批量删除类目")
    @Log(title = "类目管理", businessType = BusinessType.DELETE)
    @DeleteMapping
    public AjaxResult deleteCategory(@RequestBody String[] categoryIds) {
        int result = categoryService.deleteCategoryBatch(categoryIds);
        return result > 0 ? success() : error();
    }

    /**
     * 查询类目列表
     */
    @Operation(summary = "查询类目列表")
    @Log(title = "类目管理", businessType = BusinessType.OTHER)
    @GetMapping
    public ListCategoryResponseBody listCategory(@RequestBody CategorySelectDTO categorySelectDTO) {
        return categoryService.listCategory(categorySelectDTO);
    }

}
